﻿using System;
using ebc.coordinator.contract;
using ebc.message.contract;

namespace ebc.coordinator {
    public class Coordinator : ICoordinator {
        private string request;
        private string result;


        public void ProcessCoordinatorRequest(CoordinatorRequest coordinatorRequest) {
            request = coordinatorRequest.FromSource + "=>ProcessCoordinatorRequest <Coordinator-Input>" + Environment.NewLine;
            OnWorker(new WorkerRequest { FromSource = request + "=>Coordinator <Outpunt>" + Environment.NewLine });
        }

        public void ProcessWorkerResult(WorkerResult workerResult) {
            result = workerResult.FromTarget + "=>ProcessWorkerResult <Coordinator-ResultInput>" + Environment.NewLine;
            OnCoordinatorResult(new CoordinatorResult { FromTarget = result + "=>Coordinator <ResultOutput>" + Environment.NewLine });
        }

        public event Action<CoordinatorResult> OnCoordinatorResult;
        public event Action<WorkerRequest> OnWorker;

    }
}